package com.example.controller;


import com.example.common.Result;
import com.example.entity.PatientVisit;
import com.example.service.PatientVisitService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 就诊记录表前端操作接口
 **/
@RestController
@RequestMapping("/PatientVisit")
public class PatientVisitController {

    @Resource
    private PatientVisitService patientVisitService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody PatientVisit PatientVisit) {
        patientVisitService.add(PatientVisit);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        patientVisitService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        patientVisitService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody PatientVisit PatientVisit) {
        patientVisitService.updateById(PatientVisit);
        return Result.success();
    }

    /**
     * 修改结束问诊日期
     * @param PatientVisit
     * @return
     */
    @PutMapping("/updateEndTime")
    public Result updateEndTime(@RequestBody PatientVisit PatientVisit) {
        patientVisitService.updateEndTime(PatientVisit);
        return Result.success();
    }

    /**
     * 修改是否住院状态
     * @param PatientVisit
     * @return
     */
    @PutMapping("/updateHospitalizedStatus")
    public Result updateHospitalizedStatus(@RequestBody PatientVisit PatientVisit) {
        patientVisitService.updateHospitalizedStatus(PatientVisit);
        return Result.success();
    }
    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        PatientVisit PatientVisit = patientVisitService.selectById(id);
        return Result.success(PatientVisit);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(PatientVisit PatientVisit) {
        List<PatientVisit> list = patientVisitService.selectAll(PatientVisit);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(PatientVisit PatientVisit,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<PatientVisit> page = patientVisitService.selectPage(PatientVisit, pageNum, pageSize);
        return Result.success(page);
    }

}